package com.ruoyi.yuwen.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yuwen.domain.Commission;
import com.ruoyi.yuwen.service.ICommissionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 佣金Controller
 * 
 * @author ruoyi
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/yuwen/commission")
public class CommissionController extends BaseController
{
    @Autowired
    private ICommissionService commissionService;

    /**
     * 查询佣金列表
     */
    @PreAuthorize("@ss.hasPermi('yuwen:commission:list')")
    @GetMapping("/list")
    public TableDataInfo list(Commission commission)
    {
        startPage();
        List<Commission> list = commissionService.selectCommissionList(commission);
        return getDataTable(list);
    }

    /**
     * 导出佣金列表
     */
    @PreAuthorize("@ss.hasPermi('yuwen:commission:export')")
    @Log(title = "佣金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Commission commission)
    {
        List<Commission> list = commissionService.selectCommissionList(commission);
        ExcelUtil<Commission> util = new ExcelUtil<Commission>(Commission.class);
        util.exportExcel(response, list, "佣金数据");
    }

    /**
     * 获取佣金详细信息
     */
    @PreAuthorize("@ss.hasPermi('yuwen:commission:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commissionService.selectCommissionById(id));
    }

    /**
     * 新增佣金
     */
    @PreAuthorize("@ss.hasPermi('yuwen:commission:add')")
    @Log(title = "佣金", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Commission commission)
    {
        return toAjax(commissionService.insertCommission(commission));
    }

    /**
     * 修改佣金
     */
    @PreAuthorize("@ss.hasPermi('yuwen:commission:edit')")
    @Log(title = "佣金", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Commission commission)
    {
        return toAjax(commissionService.updateCommission(commission));
    }

    /**
     * 删除佣金
     */
    @PreAuthorize("@ss.hasPermi('yuwen:commission:remove')")
    @Log(title = "佣金", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commissionService.deleteCommissionByIds(ids));
    }
}
